﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using SlamDunk.CMS.Model.DataModel;

namespace SlamDunk.CMS.Model.ViewModel
{
    /// <summary>
    /// Article视图模型类（添加信息用）
    /// </summary>
    public class ArticleViewForWrite
    {
        #region 01.属性——Id
        /// <summary>
        /// 属性——Id
        /// </summary>
        public int Id { get; set; }
        #endregion

        #region 02.属性——ChannelId
        /// <summary>
        /// 属性——ChannelId
        /// </summary>
        public int ChannelId { get; set; }
        #endregion

        #region 03.属性——UserId
        /// <summary>
        /// 属性——UserId
        /// </summary>
        public int UserId { get; set; }
        #endregion

        #region 04.属性——Title
        /// <summary>
        /// 属性——Title
        /// </summary>
        [Required(ErrorMessage = "必填")]
        [StringLength(32, ErrorMessage = "内容过长")]
        public string Title { get; set; }
        #endregion

        #region 03.属性——Intitle
        /// <summary>
        /// 属性——Intitle
        /// </summary>
        public string Intitle { get; set; }
        #endregion

        #region 04.属性——SubTitle
        /// <summary>
        /// 属性——SubTitle
        /// </summary>
        public string SubTitle { get; set; }
        #endregion

        #region 05.属性——Author
        /// <summary>
        /// 属性——Author
        /// </summary>
        [Required(ErrorMessage = "必填")]
        [StringLength(16, ErrorMessage = "内容过长")]
        public string Author { get; set; }
        #endregion

        #region 06.属性——Source
        /// <summary>
        /// 属性——Source
        /// </summary>
        [StringLength(16, ErrorMessage = "内容过长")]
        public string Source { get; set; }
        #endregion

        #region 07.属性——Content
        /// <summary>
        /// 属性——Content
        /// </summary>
        public string Content { get; set; }
        #endregion

        #region 08.属性——IsTop
        /// <summary>
        /// 属性——IsTop
        /// </summary>
        public bool? IsTop { get; set; }
        #endregion

        #region 09.属性——ImagePath
        /// <summary>
        /// 属性——ImagePath
        /// </summary>
        [DisplayName("图片路径")]
        [StringLength(256, ErrorMessage = "内容过长")]
        public string ImagePath { get; set; }
        #endregion

        #region 10.属性——ThumbPath
        /// <summary>
        /// 属性——ThumbPath
        /// </summary>
        [DisplayName("缩略图路径")]
        [StringLength(256, ErrorMessage = "内容过长")]
        public string ThumbPath { get; set; }
        #endregion

        #region 11.属性——Attachment
        /// <summary>
        /// 属性——Attachment
        /// </summary>
        public string Attachment { get; set; }
        #endregion

        #region 12.方法——转换为数据模型
        /// <summary>
        /// 方法——转换为数据模型
        /// </summary>
        /// <returns>数据模型对象</returns>
        public Article ToDataModel()
        {
            return new Article
            {
                Id = this.Id,
                ChannelId = this.ChannelId,
                UserId = this.UserId,
                Title = this.Title,
                Intitle = this.Intitle,
                SubTitle = this.SubTitle,
                Author = this.Author,
                Source = this.Source,
                Content = this.Content,
                ImagePath = this.ImagePath,
                ThumbPath = this.ThumbPath,
                Sort = 0,
                Click = 0,
                IsTop = this.IsTop,
                SaveDirectory = string.Format("/{0}/{1}/{2}/", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day),
                FileName = Guid.NewGuid().ToString(),
                FileExtName = ".html",
                Publish = true,
                DelFlag = false,
                AddTime = DateTime.Now,
            };
        }
        #endregion
    }
}
